package com.ai.async;

import com.ai.util.GetCameraInfoHk;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.stream.Collectors;

/**
 * @Author jiaok
 * @Date 2024-12-30 14:59
 */
@Component
public class BatchGetCameraStatusAsync {



   public static ExecutorService executorService = Executors.newFixedThreadPool(20);

    /**
     * 获取摄像头状态任务
     */
    public static class GetCameraStatusFromPlatTask implements Callable<Map<Integer, Long>>{

        /**
         * 取流平台id
         */
        private Integer platId;

        /**
         * 摄像头code列表
         */
        private List<String> cameraCodes;

        private GetCameraInfoHk getCameraInfoHk;

        public GetCameraStatusFromPlatTask(Integer platId, List<String> cameraCodes,GetCameraInfoHk getCameraInfoHk) {
            this.platId = platId;
            this.cameraCodes = cameraCodes;
            this.getCameraInfoHk = getCameraInfoHk;
        }

        @Override
        public Map<Integer, Long> call() throws Exception {
            Map<String, Integer> cameraStatusMap = getCameraInfoHk.getCameraStatusMap(platId, cameraCodes);
            //统计各状态的数量
            return cameraStatusMap.values().stream().collect(Collectors.groupingBy(value -> value, Collectors.counting()));
        }
    }

}
